package com.think.service.exp;

import com.think.service.model.ResultModel;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

public class BusinessExp extends RuntimeException implements CustomExp {

    private String code;
    private String msg;
    private Integer statusCode;

    public BusinessExp() {
    }

    public BusinessExp(String msg) {
        super(msg);
        this.msg = msg;
    }

    public BusinessExp(String code, String msg) {
        super(msg);
        this.msg = msg;
        this.code = code;
    }

    public BusinessExp(String code, String msg, Integer statusCode) {
        super(msg);
        this.msg = msg;
        this.code = code;
        this.statusCode = statusCode;
    }


    @Override
    public ResponseEntity<ResultModel> handleExp(BusinessExp e) {
        ResultModel resultModel = new ResultModel(e.code, e.msg);
        int statusCode = e.statusCode == null ? HttpStatus.INTERNAL_SERVER_ERROR.value() : e.statusCode;
        return new ResponseEntity(resultModel, HttpStatus.valueOf(statusCode));
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Integer getStatusCode() {
        return statusCode;
    }

    public void setStatusCode(Integer statusCode) {
        this.statusCode = statusCode;
    }
}
